package com.ct.controller.shipping;

import com.ct.application.shipping.model.po.ChuanYuanDiaoPeiJieTiSavePO;
import com.ct.application.shipping.model.po.ChuanYuanDiaoPeiSearchPO;
import com.ct.application.shipping.model.po.ChuanYuanDiaoPeiShangChuanSavePO;
import com.ct.application.shipping.model.po.ChuanYuanDiaoPeiXiaChuanSavePO;
import com.ct.application.shipping.model.vo.ChuanYuanDiaoPeiJieVO;
import com.ct.application.shipping.model.vo.ChuanYuanDiaoPeiVO;
import com.ct.application.shipping.model.vo.ChuanYuanZhiWeiVO;
import com.ct.application.shipping.service.ChuanYuanDiaoPeiService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.ApiLog;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * 船员调配
 */
@RestController
@PermissionApi(title = "船员调配",path="/api/v1/chuanyuandiaopei",code = "cydp1000",sorted = 31)
public class ChuanYuanDiaoPeiController extends BaseController {

    @Resource
    private ChuanYuanDiaoPeiService diaoPeiService;


    /**
     * 查询船员调配数据
     */
    @PostMapping("/chuanyuandiaopei/list")
    @PermissionApi(title = "查询船员调配数据",path="/api/v1/chuanyuandiaopei/list",code = "cydp1001",sorted = 1)
    public List<ChuanYuanDiaoPeiVO> findChuanYuanDiaoPei(@Validated @RequestBody ChuanYuanDiaoPeiSearchPO searchPO) {
        return diaoPeiService.findChuanYuanDiaoPei(searchPO);
    }


    /**
     * 上船
     */
    @PostMapping("/chuanyuandiaopei/shangchuan")
    @ApiLog("船员调配上船")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船员调配上船",path="/api/v1/chuanyuandiaopei/shangchuan",code = "cydp1002",sorted = 2)
    public Boolean shangchuan(@Validated @RequestBody ChuanYuanDiaoPeiShangChuanSavePO shangChuanSavePO) {
        diaoPeiService.shangChuan(shangChuanSavePO);
        return true;
    }

    /**
     * 根据id查询调配数据
     */
    @PostMapping("/chuanyuandiaopei/get/{id}")
    @PermissionApi(title = "根据id查询调配数据",path="/api/v1/chuanyuandiaopei/get/{id}",code = "cydp1003",sorted = 3)
    public ChuanYuanDiaoPeiVO getChuanYuanDiaoPeiById(@PathVariable("id") Long id) {
        return  diaoPeiService.getChuanYuanDiaoPei(id);
    }


    /**
     * 下船
     */
    @PostMapping("/chuanyuandiaopei/xiaChuan")
    @ApiLog("船员调配下船")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船员调配下船",path="/api/v1/chuanyuandiaopei/xiaChuan",code = "cydp1004",sorted = 4)
    public Boolean xiaChuan(@Validated @RequestBody ChuanYuanDiaoPeiXiaChuanSavePO xiaChuanSavePO) {
        diaoPeiService.xiaChuan(xiaChuanSavePO);
        return true;
    }


    /**
     * 保存和更新 接替
     */
    @PostMapping("/chuanyuandiaopei/saveupdatejieti")
    @ApiLog("保存和更新接替")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "保存和更新接替",path="/api/v1/chuanyuandiaopei/saveupdatejieti",code = "cydp1005",sorted = 5)
    public Boolean saveupdatejieti(@Validated @RequestBody ChuanYuanDiaoPeiJieTiSavePO jieTiSavePO) {
        if (Objects.nonNull(jieTiSavePO.getId())){
            diaoPeiService.updateJieTi(jieTiSavePO);
        }else{
            diaoPeiService.jieTi(jieTiSavePO);
        }
        return true;
    }

    /**
     * 根据id查询接替数据
     */
    @PostMapping("/chuanyuandiaopei/getJieTiXiangQing/{id}")
    @PermissionApi(title = "根据id查询接替数据",path="/api/v1/chuanyuandiaopei/getJieTiXiangQing/{id}",code = "cydp1006",sorted = 6)
    public ChuanYuanDiaoPeiJieVO jieTiXiangQing(@PathVariable("id") Long id) {
        return diaoPeiService.jieTiXiangQing(id);
    }

    /**
     * 根据id删除接替数据
     */
    @PostMapping("/chuanyuandiaopei/delJieTi/{id}")
    @ApiLog("根据id删除接替数据")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "根据id删除接替数据",path="/api/v1/chuanyuandiaopei/delJieTi/{id}",code = "cydp1007",sorted = 7)
    public Boolean delJieTi(@PathVariable("id") Long id) {
        return diaoPeiService.delJieTi(id);
    }





    /**
     *  根据调配面板查询《离船申请》对应的职位及职位下的船员
     */
    @PostMapping("/chuanyuandiaopei/getLiChuanChuanYuan/{xinXiId}")
    @PermissionApi(title = "根据调配面板查询离船申请对应的职位及职位下的船员",path="/api/v1/chuanyuandiaopei/getLiChuanChuanYuan/{xinXiId}",code = "cydp1008",sorted = 8)
    public List<ChuanYuanZhiWeiVO> getChuanYuanList(@PathVariable("xinXiId") Long xinXiId) {
        return  diaoPeiService.getChuanYuanList(xinXiId,"离船");
    }



    /**
     *  根据调配面板查询《调令》对应的职位及职位下的船员
     */
    @PostMapping("/chuanyuandiaopei/getDiaoLingChuanYuan/{xinXiId}")
    @PermissionApi(title = "根据调配面板查询调令对应的职位及职位下的船员",path="/api/v1/chuanyuandiaopei/getDiaoLingChuanYuan/{xinXiId}",code = "cydp1009",sorted = 9)
    public List<ChuanYuanZhiWeiVO> getDiaoLingChuanYuan(@PathVariable("xinXiId") Long xinXiId) {
        return diaoPeiService.getChuanYuanList(xinXiId,"调令");
    }
}
